/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * newBugView.java
 *
 * Created on 16.01.2010, 22:41:21
 */

package jasebt_app;

import base.Bug;
import base.Project;
import base.Tools;
import base.User;
import java.io.File;
import java.io.IOException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.SAXException;
import xmlparser.xmlWriter;
import org.jdesktop.application.Action;
import xmlparser.bugParser;
import xmlparser.deviceParser;
import xmlparser.projectParser;
import xmlparser.stateParser;
import xmlparser.userParser;
/**
 *
 * @author Pavel Belov
 */
public class reopenedBugsView extends javax.swing.JDialog {

    SAXParser parser = null;

    public static User user[];
    public String state[];
    public static String device[];
    public static Project project[];

    public static String DBPATH = "DB" + File.separator;    
    /** Creates new form newBugView */
    public reopenedBugsView(java.awt.Frame parent) {
        super(parent);
        initComponents();
        this.setTitle("Reopened bugs");



//        jTable.setValueAt("Bbbuggg", 0, 0);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        bCancel = new javax.swing.JButton();

        setModal(true);
        setName("Form"); // NOI18N
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(jasebt_app.Jasebt_appApp.class).getContext().getActionMap(reopenedBugsView.class, this);
        bCancel.setAction(actionMap.get("closenewBugForm")); // NOI18N
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(jasebt_app.Jasebt_appApp.class).getContext().getResourceMap(reopenedBugsView.class);
        bCancel.setText(resourceMap.getString("bCancel.text")); // NOI18N
        bCancel.setName("bCancel"); // NOI18N
        bCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bCancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(468, Short.MAX_VALUE)
                .addComponent(bCancel)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(300, Short.MAX_VALUE)
                .addComponent(bCancel)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void bCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bCancelActionPerformed
}//GEN-LAST:event_bCancelActionPerformed

    // Search for bugs
    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
    }//GEN-LAST:event_formWindowClosed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bCancel;
    // End of variables declaration//GEN-END:variables

    @Action public void closenewBugForm() {
        dispose();
    }
    // returning users count
    private int OpenUsersDB() throws IOException, SAXException {
        int count = 0;
        userParser up = new userParser();
        File usersFile = new File(DBPATH + "users.xml");

        if (usersFile.exists() == true) {
            parser.parse(usersFile, up);
            count = up.getCount();
            user = new User[count];
            up.fill(user);
            System.out.println("Users count = " + count);
        }

        return count;
    }

    private int OpenStatesDB() throws SAXException, IOException {
        int count = 0;
        stateParser sp = new stateParser();
        File statesFile = new File(DBPATH + "states.xml");

        if (statesFile.exists() == true) {
            parser.parse(statesFile, sp);
            count = sp.getCount();
            state = new String[count];
            sp.fill(state);
        }

        return count;
    }
    private int OpenDevicesDB() throws SAXException, IOException {
        int count = 0;
        deviceParser dp = new deviceParser();
        File deviceFile = new File(DBPATH + "devices.xml");

        if (deviceFile.exists() == true) {
            parser.parse(deviceFile, dp);
            count = dp.getCount();
            device = new String[count];
            dp.fill(device);
        }

        return count;
    }

    private int OpenProjectsDB() throws SAXException, IOException {
        int count = 0;
        projectParser sp = new projectParser();
        File projectsFile = new File(DBPATH + "projects.xml");

        if (projectsFile.exists()) {
            parser.parse(projectsFile, sp);
            count = sp.getCount();
            System.out.println("count projects = " + count);
            project = new Project[count];
            sp.fill(project);
        }

        return count;
    }


}
